var pic = 'https://img2.woyaogexing.com/2022/09/26/44285b4b684b40e1!400x400.jpg';
var vm = new Vue({
    el:"#app",
    data:{//负责定义响应式数据
        btnArr:['综合排序','距离最近','销量最高','筛选'],
        list:[
            {name:'秋刀鱼',price:88,pic,count:1},
            {name:'大黄鱼',price:77,pic,count:2},
            {name:'皮皮虾',price:99,pic,count:3},
        ]
    },
    methods:{//负责定义方法
        add(item){
            item.count++;
        },
        sub(item){
            if(item.count > 0) item.count--;
        },
        clean(){
            this.list = [];
        },
        mysort(index){
            if(index == 0){
                this.list.sort((a,b)=>{
                    return a.price - b.price;
                })
            }
            else if(index == 2){
                this.list.sort((a,b)=>{
                    return b.count - a.count;
                })
            }
        }
    }
})